home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / QRTEE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  8.5 KB  |  327 lines

  1. {**********************************************}
  2. {  TChart 4.0 --> QuickReports 2.0 & 3.0       }
  3. {  Copyright (c) 1996-98 by David Berneda      }
  4. {  All Rights Reserved                         }
  5. {**********************************************}
  6. {$I teedefs.inc}
  7. unit QrTee;
  8.  
  9. interface
  10.  
  11. uses
  12.   WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls,
  13.   Forms, Dialogs, TeeProcs, TeEngine, Chart, QuickRpt, TeCanvas,
  14.   {$IFNDEF NOUSE_BDE}
  15.   DBChart,
  16.   {$ENDIF} StdCtrls, Menus, ExtCtrls;
  17.  
  18. type
  19.   TTeeQuickMethod=(qtmBitmap,qtmMetafile);
  20.  
  21.   TQRChart=class;
  22.  
  23.   TQRDBChart=class({$IFNDEF NOUSE_BDE}TCustomDBChart{$ELSE}TCustomChart{$ENDIF})
  24.   protected
  25.   public
  26.     constructor Create(AOwner : TComponent); override;
  27.     Function GetRectangle:TRect; override;
  28.     procedure Invalidate; override;
  29.     procedure Paint; override;
  30.   published
  31.     {$IFNDEF NOUSE_BDE}
  32.     { TCustomDBChart properties }
  33.     property ShowGlassCursor;
  34.     { TCustomDBChart events }
  35.     property OnProcessRecord;
  36.     {$ENDIF}
  37.  
  38.     { TCustomChart Properties }
  39.     property BackImage;
  40.     property BackImageInside;
  41.     property BackImageMode;
  42.     property BackWall;
  43.     property BottomWall;
  44.     property Foot;
  45.     property Gradient;
  46.     property LeftWall;
  47.     property MarginBottom;
  48.     property MarginLeft;
  49.     property MarginRight;
  50.     property MarginTop;
  51.     property Title;
  52.  
  53.     { TCustomChart Events }
  54.     property OnGetLegendPos;
  55.     property OnGetLegendRect;
  56.  
  57.     { TCustomAxisPanel properties }
  58.     property AxisVisible;
  59.     property BackColor;
  60.     property BottomAxis;
  61.     property Chart3DPercent;
  62.     property ClipPoints;
  63.     property DepthAxis;
  64.     property Frame;
  65.     property LeftAxis;
  66.     property Legend;
  67.     property MaxPointsPerPage;
  68.     property Page;
  69.     property RightAxis;
  70.     property ScaleLastPage;
  71.     property SeriesList;
  72.     property TopAxis;
  73.     property View3D;
  74.     property View3DOptions;
  75.     property View3DWalls;
  76.  
  77.     { TCustomAxisPanel events }
  78.     property OnAfterDraw;
  79.     property OnBeforeDrawAxes;
  80.     property OnBeforeDrawSeries;
  81.     property OnGetAxisLabel;
  82.     property OnGetLegendText;
  83.     property OnGetNextAxisLabel;
  84.     property OnPageChange;
  85.  
  86.     { TPanel properties }
  87.     property BevelInner;
  88.     property BevelWidth;
  89.     property BevelOuter default bvNone;
  90.     property BorderWidth;
  91.     property BorderStyle;
  92.     property Color default clWhite;
  93.     property DragCursor;
  94.     property DragMode;
  95.     property ParentColor;
  96.     property ParentShowHint;
  97.     property PopupMenu;
  98.     property ShowHint;
  99.  
  100.     { TPanel events }
  101.     property OnClick;
  102.     property OnDblClick;
  103.     property OnDragDrop;
  104.     property OnDragOver;
  105.     property OnEndDrag;
  106.     property OnEnter;
  107.     property OnExit;
  108.     property OnMouseDown;
  109.     property OnMouseMove;
  110.     property OnMouseUp;
  111.     property OnResize;
  112.     {$IFDEF D3}
  113.     property OnStartDrag;
  114.     {$ENDIF}
  115.   end;
  116.  
  117.   TPrintChartEvent = procedure( Sender: TQRChart; 
  118.                 Var PaperRect,ChartRect:TRect ) of object;
  119.  
  120.   TQRChart = class(TQRPrintable)
  121.   private
  122.     { Private declarations }
  123.     FOnPrint        : TPrintChartEvent;
  124.     FTeePrintMethod : TTeeQuickMethod;
  125.     
  126.     Function GetChart:TQRDBChart;
  127.     Procedure SetPrintMethod(Value:TTeeQuickMethod);
  128.     {$IFDEF D1}
  129.     Function Previewing:Boolean;
  130.     {$ENDIF}
  131.   protected
  132.     { Protected declarations }
  133.     procedure ReadState(Reader: TReader); override;
  134.   public
  135.     { Public declarations }
  136.     Constructor Create(AOwner : TComponent); override;
  137.     procedure Print(OfsX, OfsY : integer); override;
  138.     procedure Paint; override;
  139.   published
  140.     { Published declarations }
  141.     property Chart : TQRDBChart read GetChart;
  142.     property TeePrintMethod:TTeeQuickMethod read FTeePrintMethod
  143.                                             write SetPrintMethod default qtmMetafile;
  144.     { Published QR events }
  145.     property OnPrint:TPrintChartEvent read FOnPrint write FOnPrint;
  146.  
  147.   end;
  148.  
  149. implementation
  150.  
  151. Uses DsgnIntf,TeeConst {$IFDEF D1},QRPrntr{$ENDIF} ;
  152.  
  153. Const TeeMsg_DefaultQRChart='QRDBChart'; { <-- dont translate }
  154.  
  155. { TQRDBChart }
  156. Constructor TQRDBChart.Create(AOwner : TComponent);
  157. begin
  158.   inherited Create(AOwner);
  159.   Color:=clWhite;
  160.   BevelOuter:=bvNone;
  161.   BufferedDisplay:=False;
  162.   SetBounds(-1,-1,1,1);
  163.   Hide;
  164. end;
  165.  
  166. Function TQRDBChart.GetRectangle:TRect;
  167. Var tmpZoomFactor : Double;
  168. begin
  169.   if Parent<>nil then
  170.   With TQRChart(Parent) do
  171.   begin
  172.     if (ParentReport<>nil) then tmpZoomFactor:=100.0/ParentReport.Zoom
  173.                            else tmpZoomFactor:=1;
  174.     result:=Rect(0,0, Round(ClientWidth*tmpZoomFactor),
  175.                       Round(ClientHeight*tmpZoomFactor) );
  176.   end;
  177. end;
  178.  
  179. procedure TQRDBChart.Paint;
  180. var Meta   : TMetaFile;
  181.     Bitmap : TBitmap;
  182. begin
  183.   if Parent<>nil then
  184.   With TQRChart(Parent) do
  185.   Case FTeePrintMethod of
  186.   qtmMetafile: begin
  187.                  Meta:=TeeCreateMetafile(True,GetRectangle);
  188.                  try
  189.                    Canvas.StretchDraw(GetClientRect,Meta);
  190.                  finally
  191.                    Meta.Free;
  192.                  end;
  193.                end;
  194.   qtmBitmap:   begin
  195.                  Bitmap:=TeeCreateBitmap(clWhite,GetRectangle);
  196.                  try
  197.                    Canvas.StretchDraw(GetClientRect,Bitmap);
  198.                  finally
  199.                    Bitmap.Free;
  200.                  end;
  201.                end;
  202.   end;
  203. end;
  204.  
  205. procedure TQRDBChart.Invalidate;
  206. begin
  207.   if Parent<>nil then Parent.Invalidate;
  208. end;
  209.  
  210. { TQRChart }
  211. Constructor TQRChart.Create(AOwner : TComponent);
  212. begin
  213.   inherited Create(AOwner);
  214.   FTeePrintMethod:=qtmMetafile;
  215.   Width :=350;
  216.   Height:=200;
  217.   if (csDesigning in ComponentState) and
  218.      (not (csLoading in Owner.ComponentState)) then
  219.   With TQRDBChart.Create(AOwner) do
  220.   begin
  221.     Parent:=TWinControl(Self);
  222.     Name:=TeeGetUniqueName(AOwner,TeeMsg_DefaultQRChart);
  223.     Title.Text.Clear;
  224.     Title.Text.Add(Self.ClassName);
  225.   end;
  226. end;
  227.  
  228. procedure TQRChart.ReadState(Reader: TReader);
  229. Var tmpChart:TQRDBChart;
  230. begin
  231.   tmpChart:=Chart;
  232.   if (tmpChart<>nil) and
  233.      (not (csLoading in tmpChart.ComponentState))
  234.      {$IFNDEF D1}
  235.      and (not (csAncestor in tmpChart.ComponentState))
  236.      {$ENDIF}
  237.         then
  238.           tmpChart.Free;
  239.   inherited ReadState(Reader);
  240. end;
  241.  
  242. Procedure TQRChart.SetPrintMethod(Value:TTeeQuickMethod);
  243. begin
  244.   if Value<>FTeePrintMethod then
  245.   begin
  246.     FTeePrintMethod:=Value;
  247.     Repaint;
  248.   end;
  249. end;
  250.  
  251. {$IFDEF D1}
  252. Function TQRChart.Previewing:Boolean;
  253. begin
  254.   result:=(QRPrinter<>nil) and (QRPrinter.Destination=qrdMetafile);
  255. end;
  256. {$ENDIF}
  257.  
  258. procedure TQRChart.Print(OfsX, OfsY : Integer);
  259. Var tmpMeta   : TMetafile;
  260.     QuickRect : TRect;
  261.     tmpRect   : TRect;
  262.     tmpChart  : TQRDBChart;
  263.     tmpBitmap : TBitmap;
  264. begin
  265.   tmpChart:=Chart;
  266.   if tmpChart<>nil then
  267.   begin
  268.     {$IFNDEF NOUSE_BDE}
  269.     tmpChart.RefreshData;
  270.     {$ENDIF}
  271.     With ParentReport.QRPrinter do
  272.     begin
  273.       QuickRect:=Rect( Xpos(OfsX+Size.Left),
  274.                        Ypos(OfsY+Size.Top),
  275.                        Xpos(OfsX+Size.Left+Size.Width),
  276.                        Ypos(OfsY+Size.Top+Size.Height));
  277.  
  278.       tmpRect:=tmpChart.GetRectangle;
  279.  
  280.       if Assigned( FOnPrint ) then FOnPrint( Self, QuickRect, tmpRect );
  281.  
  282.       Case FTeePrintMethod of
  283.       qtmMetafile: begin
  284.                      tmpMeta:=tmpChart.TeeCreateMetafile(True, tmpRect);
  285.                      try
  286.                        {$IFDEF D1}
  287.                        if Previewing then
  288.                           tmpChart.DrawToMetaCanvas(Canvas,QuickRect)
  289.                        else
  290.                           Canvas.StretchDraw(QuickRect,tmpMeta);
  291.                        {$ELSE}
  292.                        Canvas.StretchDraw(QuickRect,tmpMeta);
  293.                        {$ENDIF}
  294.                      finally
  295.                        tmpMeta.Free;
  296.                      end;
  297.                    end;
  298.         qtmBitmap: begin
  299.                      tmpBitmap:=tmpChart.TeeCreateBitmap(clWhite, tmpRect);
  300.                      try
  301.                        Canvas.StretchDraw(QuickRect,tmpBitmap);
  302.                      finally
  303.                        tmpBitmap.Free;
  304.                      end;
  305.                    end;
  306.       end;
  307.     end;
  308.   end;
  309.   inherited Print(OfsX,OfsY);
  310. end;
  311.  
  312. procedure TQRChart.Paint;
  313. begin
  314.   if Chart<>nil then Chart.Paint;
  315.   inherited Paint;
  316. end;
  317.  
  318. Function TQRChart.GetChart:TQRDBChart;
  319. begin
  320.   if ControlCount>0 then result:=TQRDBChart(Controls[0])
  321.                     else result:=nil;
  322. end;
  323.  
  324. initialization
  325.   RegisterClass( TQRDBChart );
  326. end.
  327.